package com.gaogzhen.security.lock;

import lombok.extern.slf4j.Slf4j;
import org.openjdk.jol.info.ClassLayout;

@Slf4j(topic = "s.RevokeBiasedLock")
public class RevokeBiasedLock {
    public static void main(String[] args) {
        Person p = new Person();
         new Thread(() -> {
            log.debug(ClassLayout.parseInstance(p).toPrintable());
            synchronized (p) {
                log.debug(ClassLayout.parseInstance(p).toPrintable());
            }
            log.debug(ClassLayout.parseInstance(p).toPrintable());
            synchronized (RevokeBiasedLock.class) {
                RevokeBiasedLock.class.notify();
            }
        }, "t1").start();

       new Thread(() -> {
            synchronized (RevokeBiasedLock.class) {
                try {
                    RevokeBiasedLock.class.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            log.debug(ClassLayout.parseInstance(p).toPrintable());
            synchronized (p) {
                log.debug(ClassLayout.parseInstance(p).toPrintable());
            }
            log.debug(ClassLayout.parseInstance(p).toPrintable());
        }, "t2").start();
    }
}
